<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no" />
    <title>ref的使用</title>
    <style>
        [v-cloak] {
            display: none;
        }
    </style>
</head>

<body>
    <div id="app" v-cloak></div>
    <script src="js/vue.js"></script>
    <script>
        let App = {
            template: `
            <div>我是app组件</div>
        `,
            methods: {
                send() {
                    console.log("我是子组件里面的方法");
                }
            }
        };
        new Vue({
            el: "#app",
            template: `
            <div>
                <div class="box1" ref="box1">我是第一个盒子</div>
                <div class="box2" ref="box2">我是第二个盒子</div>
                <div class="box3" ref="box3">我是第三个盒子</div>
                <App ref="app"></App>
            </div>
        `,
            data() {
                return {

                }
            },
            components: {
                App
            },
            computed: {

            },
            mounted() {
                console.log(this.$refs.box1.innerHTML);
                //获取父元素
                console.log(this.$refs.box1.parentNode.innerHTML);
                //获取下一个元素
                console.log(this.$refs['box2'].nextElementSibling);
                //获取上一个元素
                console.log(this.$refs['box2'].previousElementSibling);

                //调用子组件里面的方法
                this.$refs['app'].send();

            }
        })
    </script>
</body>

</html>